package com.zy.gpdemo.controller;

import com.alibaba.fastjson.JSON;
import com.zy.gpdemo.service.PrinterService;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/printer")
public class PrinterController {
	
	@Resource
    PrinterService printerService;

    @PostMapping("/start")
    boolean startAll(){
        return printerService.startAllPrinter();
    }

    @PostMapping("/stop")
    boolean stopAll(){
         printerService.stopAllPrinter();
         return true;
    }

    @PostMapping("/start/{ip}")
    boolean start(@PathVariable String ip){
        return printerService.startPrinterByIP(ip);
    }

    @PostMapping("/stop/{ip}")
    boolean stop(@PathVariable String ip){
        return printerService.stopPrinterByIP(ip);
    }
    
    @PostMapping("/init")
    boolean init(){
        return printerService.initPrinter();
    }
    
    @PostMapping("/reprint/{ip}/{msgId}")
    boolean rePrint(@PathVariable String ip, @PathVariable String msgId){
        return printerService.rePrintByIP(ip, msgId);
    }

    @PostMapping("/add/{ip1}/{ip2}")
    boolean addIP(@PathVariable String ip1, @PathVariable String ip2){
        return printerService.addIP(ip1, ip2);
    }

    @PostMapping("/remove/{ip1}/{ip2}")
    boolean removeIP(@PathVariable String ip1, @PathVariable String ip2){
        return printerService.remove(ip1, ip2);
    }

    @GetMapping("/status")
    String getAllPrinterStatus(){
        return JSON.toJSONString(printerService.getAllStatus());
    }

    @GetMapping("/status/{ip}")
    String getPrinterStatus(@PathVariable String ip){
        return JSON.toJSONString(printerService.getStatusByIP(ip));
    }

}
